package test;

import java.util.*;

public class WangYi4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] input = new int[m][2];
        for (int i = 0; i < m; i++) {
            input[i][0] = scanner.nextInt();
            input[i][1] = scanner.nextInt();
        }
        System.out.println(getRes(input,num));
    }

    private static int getRes(int[][] input, int num) {
        boolean[][] booleans = new boolean[num][num];
        for (int i = 0; i < input.length; i++) {
            List<Integer> listRenKe = getRenKe(input[i][0],input);
            if (!listRenKe.isEmpty()){
                for (Integer item : listRenKe) {
                    booleans[input[i][0] - 1][item - 1] = true;
                }
            }
        }
        int count = 0;
        for (int i = 0; i < num; i++) {
            for (int j = 0; j < i; j++) {
                if (isLegal(booleans,i,j)){
                    count ++;
                }
            }
        }

        return count;
    }

    private static List<Integer> getRenKe(int start, int[][] input) {
        List<Integer> list = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();
        Set<Integer> memo = new HashSet<>();
        stack.push(start);
        memo.add(start);
        while (!stack.empty()){
            int cur = stack.pop();
            memo.add(cur);
            for (int i = 0; i < input.length; i++) {
                if (input[i][0] == cur && !memo.contains(input[i][1])){
                    stack.add(input[i][1]);
                    memo.add(input[i][1]);
                    list.add(input[i][1]);
                }
            }
        }
        return list;
    }

    private static boolean isLegal(boolean[][] booleans, int i, int j) {
        if (booleans[i][j] && booleans[j][i]){
            return true;
        }
        return false;
    }
}
